﻿using FS.Common.DotNetBean;
using FS.Common.DotNetCode;
using FS.Common.DotNetUI;
using FS.Common.DotNetData;
using FS.Business;
using System;
using System.Collections;
using System.Data;

namespace FS.Web.BLL.Visa_info
{
    public partial class Visa_InfoAuditForm :PageBase
    {
        private string _key;
        private visa_dao _visa = new visa_dao();
        protected void Page_Load(object sender, EventArgs e)
        {
            this._key = base.Request["key"];
            if (!base.IsPostBack)
            {
                GetSelect_City();
                //GetSelect_Operation();
                GetSelect_moneytype();
                GetSelect_moneyflag();
                GetSelect_Supply();
                GetSelect_Dataintegrity();
                GetSelect_InfoFlag();
                if (!string.IsNullOrEmpty(this._key))
                {
                    this.InitData();
                }

                #region 权限控制
                string ls_viewSupply = RequestSession.GetSessionUser().isViewSupply;
                string ls_viewPrice = RequestSession.GetSessionUser().isViewPrice;
                string ls_viewCost = RequestSession.GetSessionUser().isViewCost;
                if (ls_viewSupply == "0")
                {
                    this.div_supply.Visible = false;
                }
                if (ls_viewPrice == "0")
                {
                    this.div_price.Visible = false;
                }
                if (ls_viewCost == "0")
                {
                    this.div_cost.Visible = false;
                }
                #endregion
            }
        }

        #region 下拉数据
        //所属国家
        private void GetSelect_City()
        {
            DataTable dt = _visa.GetSelect_CityInfo();
            ControlBindHelper.BindHtmlSelect(dt, this.City_id, "city_name", "city_id", "");
        }

        //签证类型
        private void GetSelect_CertType(string ls_city)
        {
            DataTable dt = _visa.GetSelect_CertTypeInfoByCityID(ls_city);
            ControlBindHelper.BindHtmlSelect(dt, this.Ref_CertType, "name", "id", "");
        }

        //供应商
        private void GetSelect_Supply()
        {

          DataTable dt = _visa.GetSelect_SupplyInfoSimple();
          ControlBindHelper.BindHtmlSelect(dt, this.Supply_id, "supply_name", "supply_id", "请选择");
        }
        
        //经办人
        private void GetSelect_Operation(string ls_city)
        {
            DataTable dt = _visa.Ajax_GetCityUser(ls_city);
            ControlBindHelper.BindHtmlSelect(dt, this.InfoDetail_operationid, "text", "user_id", "");
        }
        //收款方式
        private void GetSelect_moneytype()
        {
            DataTable dt = _visa.GetSelect_moneytype();
            ControlBindHelper.BindHtmlSelect(dt, this.Ref_moneytype, "property_value", "property_key", "");
        }

        //收款情况
        private void GetSelect_moneyflag()
        {
            DataTable dt = _visa.GetSelect_moneyflag();
            ControlBindHelper.BindHtmlSelect(dt, this.Ref_moneyflag, "property_value", "property_key", "");
        }
        //资料
        private void GetSelect_Dataintegrity()
        {
            DataTable dt = _visa.GetSelect_Dataintegrity();
            ControlBindHelper.BindHtmlSelect(dt, this.Data_integrity, "property_value", "property_key", "");
        }
        //订单状态
        private void GetSelect_InfoFlag()
        {
            DataTable dt = _visa.GetSelect_InfoFlagBeforeStep(2);
            ControlBindHelper.BindHtmlSelect(dt, this.ref_infoflag, "property_value", "property_key", "");
        }

        #endregion

        private void InitData()
        {
            Hashtable ht = _visa.GetInfoAuditForm(this._key);
            if (ht.Count > 0 && ht != null)
            {
                string ls_city = ht["CITY_ID"].ToString();
                string ls_certtype = ht["REF_CERTTYPE"].ToString();
                //显示过滤后的下拉框
                this.GetSelect_CertType(ls_city);
                this.GetSelect_Operation(ls_city);
                //this.GetSelect_Supply(ls_city, ls_certtype);                

                ControlBindHelper.SetWebControls(this.Page, ht);
                this.HuserAudit.Value = ht["USER_AUDIT"].ToString();
                this.Hopeator.Value = ht["INFODETAIL_OPERATIONID"].ToString();
            }
        }
        protected void Save_Click(object sender, EventArgs e)
        {
            Hashtable ht = new Hashtable();
            ht = ControlBindHelper.GetWebControls(this.Page);
            //string ls_userid = RequestSession.GetSessionUser().UserId.ToString();
            //string ls_username = RequestSession.GetSessionUser().UserName.ToString();
            
            if (!string.IsNullOrEmpty(this._key))
            {               
                ht["ModifyDate"] = DateTime.Now;
                ht["ModifyUserId"] = _userid;
                ht["ModifyUserName"] = _username;
                ht["user_audit"] = _disname;
            }
            ht.Remove("HuserAudit");
            ht.Remove("Hopeator");
            if (string.IsNullOrEmpty(ht["ref_infoflag"].ToString()))
            {
                ht.Remove("ref_infoflag");
            }
            if (string.IsNullOrEmpty(ht["InfoDetai_EndPrice"].ToString()))
            {
                ht["InfoDetai_EndPrice"] = 0;
            }

            bool IsOk = DataFactory.Run().Submit_AddOrEdit("Visa_InfoDetail", "InfoDetail_ID", this._key, ht);
            if (IsOk)
            {
                ShowMsgHelper.AlertMsg("操作成功！");
            }
            else
            {
                ShowMsgHelper.Alert_Error("操作失败！");
            }
        }
    }
}